//
//  DDIntegralViewController.m
//  Dingdong
//
//  Created by 程强 on 16/11/11.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDIntegralViewController.h"
#import "DDIntegralTableCell.h"
#import "KSOptionMenu.h"
#import "DDUserManager.h"
#import "DDIntegralSet.h"

typedef NS_ENUM(NSInteger, DDIntegralType) {
    DDIntegralTypeAll = 0,
    DDIntegralTypeGet,
    DDIntegralTypeConsume,
};

@interface DDIntegralViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *integralView;
@property (weak, nonatomic) IBOutlet UITableView *integralTable;
@property (strong, nonatomic) DDUserManager *manager;
@property (strong, nonatomic) DDIntegralSet *myIntegralSet;
@end

@implementation DDIntegralViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.manager = [DDUserManager new];
    [self layoutIntegralView];
    [self fetchIntegral];
}
- (void)layoutIntegralView
{
    self.integralView.layer.cornerRadius = self.integralView.bounds.size.height/2.0;
    self.integralView.layer.borderWidth = 2.0;
    self.integralView.layer.borderColor = RGBColor(238, 162, 162).CGColor;
}
#pragma mark --- 获取积分
- (void)fetchIntegral
{
    weak_Self(self);
    [[self.manager myIntegral:DDIntegralTypeAll pageNumber:1 pageSize:10]subscribeNext:^(id x) {
        weakSelf.myIntegralSet = x;
    } error:^(NSError *error) {
        
    } completed:^{
        
    }];
}

#pragma mark --- UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *indentifier = @"IntegralCell";
    
    DDIntegralTableCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    
    if (!cell) {
        cell = [[DDIntegralTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    
    return cell;
}
- (IBAction)menuClick:(id)sender
{
    KSOptionMenu *menu = [[KSOptionMenu alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    [self.view.window addSubview:menu];
    menu.dataAry = @[@"Integration details",@"Get score detail",@"Use integral detail",@"All of it"];
}
- (IBAction)rulesClick:(id)sender
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
